﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IntoNails.Infrastructure.ViewModels;
using IntoNails.Infrastructure.Views;
using IntoNails.Models;
using IntoNails.Modules.TicketManagement.Models;

namespace IntoNails.Modules.TicketManagement.ViewModels
{
    public class TicketInteractionDialogViewModel : GenericInteractionViewModel<Ticket>, IHeaderInfoProvider<string>
    {
        #region Fields

        private string _headerInfo;
        private bool _isEditMode;
        private TicketStatus _status;

        #endregion

        public TicketInteractionDialogViewModel()
        {

        }

        #region Commands

        #endregion

        #region Implementation of IHeaderInfoProvider<string>

        public string HeaderInfo
        {
            get { return this._headerInfo; }
            set
            {
                this._headerInfo = value;
                base.RaisePropertyChanged(() => HeaderInfo);
            }
        }

        #endregion

        #region Properties

        public bool IsEditMode
        {
            get { return this._isEditMode; }
            set
            {
                this._isEditMode = value;
                base.RaisePropertyChanged(() => IsEditMode);
            }
        }

        public IEnumerable<TicketStatus> StatusValues
        {
            get
            {
                return Enum.GetValues(typeof(TicketStatus)).Cast<TicketStatus>();
            }
        }

        public TicketStatus SelectedStatus
        {
            get { return this._status; }
            set
            {
                this._status = this.InteractionEntity.Status = value;
                base.RaisePropertyChanged(() => SelectedStatus);
            }
        }

        #endregion

        public override void ViewInvoked(object parameter)
        {
            base.ViewInvoked(parameter);

            TicketDataContext dataContext = parameter as TicketDataContext;
            if (dataContext == null)
                throw new NullReferenceException("dataContext");

            this.SelectedStatus = dataContext.Status;
            this.IsEditMode = dataContext.IsEditMode;
            this.HeaderInfo = this.IsEditMode ? "Edit Ticket" : "Add New Ticket";
        }
    }
}
